package com.example.wangfanwangluo.wangfanboss.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.wangfanwangluo.wangfanboss.Models.MainModel;
import com.example.wangfanwangluo.wangfanboss.R;

import java.util.List;

/**
 * Created by wanghouyi on 2017/11/26.
 */

public class MainAdapter extends BaseAdapter {
    private Context context;
    private List<MainModel> list;
    public MainAdapter(Context context,List<MainModel> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public MainModel getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MainModel model = getItem(position);
        View view;
        ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.adapter_main, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.goodsID = (TextView)view.findViewById(R.id.work_goods_id);
            viewHolder.fromPlace = (TextView)view.findViewById(R.id.work_place_from);
            viewHolder.toPlace = (TextView)view.findViewById(R.id.work_place_to);
            viewHolder.fromName = (TextView)view.findViewById(R.id.work_name_from);
            viewHolder.toName = (TextView)view.findViewById(R.id.work_name_to);
            viewHolder.goodsType = (TextView)view.findViewById(R.id.work_goods_type);
            viewHolder.time = (TextView)view.findViewById(R.id.work_time);
            viewHolder.status = (TextView)view.findViewById(R.id.work_status);
            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder)view.getTag();
        }

        viewHolder.goodsID.setText(model.getGoodsID());
        viewHolder.fromPlace.setText(model.getFromPlace());
        viewHolder.toPlace.setText(model.getToPlace());
        viewHolder.fromName.setText("("+model.getFromName()+")");
        viewHolder.toName.setText("("+model.getToName()+")");
        viewHolder.goodsType.setText(model.getGoodsType());
        viewHolder.time.setText(model.getTime());
        viewHolder.status.setText("【"+model.getStatus()+"】");

        return view;
    }

    class ViewHolder {
        TextView goodsID;
        TextView fromPlace;
        TextView toPlace;
        TextView fromName;
        TextView toName;
        TextView goodsType;
        TextView time;
        TextView status;
    }
}
